Visual Basic (Declaration) | |
---|---|
Public Overloads Function TryUpdate( _ ByVal key As TKey, _ ByVal value As TValue _ ) As Boolean |
Parameters
- key
- The object to use as the key of the element to update.
- value
- The new value for the key if found.
Return Value
Returns true if the key provided was found and updated to the value.Exception | Description |
---|---|
System.NotSupportedException | The IDictionary is read-only. |
Library/Library.Test/TestBTreeDictionary.cs
C# | Copy Code |
---|---|
BTreeDictionary<int, string> data = new BTreeDictionary<int, string>(Comparer); Assert.IsTrue(data.TryAdd(1, "a")); Assert.IsFalse(data.TryAdd(1, "a")); Assert.IsTrue(data.TryUpdate(1, "a")); Assert.IsTrue(data.TryUpdate(1, "c")); Assert.IsTrue(data.TryUpdate(1, "d", "c")); Assert.IsFalse(data.TryUpdate(1, "f", "c")); Assert.AreEqual("d", data[1]); Assert.IsTrue(data.TryUpdate(1, "a", data[1])); Assert.AreEqual("a", data[1]); Assert.IsFalse(data.TryUpdate(2, "b")); string val; Assert.IsTrue(data.TryRemove(1, out val) && val == "a"); Assert.IsFalse(data.TryRemove(2, out val)); Assert.AreNotEqual(val, "a"); |
VB.NET | Copy Code |
---|---|
Dim data As New BTreeDictionary(Of Integer, String)(Comparer) Assert.IsTrue(data.TryAdd(1, "a")) Assert.IsFalse(data.TryAdd(1, "a")) Assert.IsTrue(data.TryUpdate(1, "a")) Assert.IsTrue(data.TryUpdate(1, "c")) Assert.IsTrue(data.TryUpdate(1, "d", "c")) Assert.IsFalse(data.TryUpdate(1, "f", "c")) Assert.AreEqual("d", data(1)) Assert.IsTrue(data.TryUpdate(1, "a", data(1))) Assert.AreEqual("a", data(1)) Assert.IsFalse(data.TryUpdate(2, "b")) Dim val As String Assert.IsTrue(data.TryRemove(1, val) AndAlso val = "a") Assert.IsFalse(data.TryRemove(2, val)) Assert.AreNotEqual(val, "a") |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7